// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/ScheduleManageApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/base/model/SchedulePlanListQueryReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'querySchedulePlanList', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },
  transList(arr, { state: { param: { xData } } }) {
    arr.forEach((item) => {
      const dataList = Object.keys(item.map || {}).map((date) => [CORE.dateStr(date), item.map[date]])
      xData.forEach((name) => {
        const key = name.slice(0, 10)
        const matched = dataList.find(([date]) => date === key)
        item[key] = matched ? matched[1] : {}
      })
    })
    return arr
  },
}
